Project Overview :

● The location of the element in the given list or the characters in the string are returned by python's index() function.
● Whether you use it on a list or a string, it always has the same syntax. String in Python is seen as a list of characters beginning at index 0.

Requirements :
 

● Python
● VS code

 
Code :
 

vowels = ['i','a', 'e', 'i', 'o','u', 'i'] print("Vowels = ", vowels) index = vowels.index("o") print('The index of o:', index) index = vowels.index("e") print('The index of e:', index) index = vowels.index("u") print('The index of u:', index) index = vowels.index("a") print('The index of a:', index) i_vowel = [ i for i in range(len(vowels)) if vowels[i] == 'i' ] print('The index of a:',i_vowel)
 
Code Explanation :
 

● Get the list of vowels and find the index of all the vowels in the list.
● Print the index value.
● vowels = ['i','a', 'e', 'i', 'o','u', 'i']
● Print the vowels.
● print("Vowels = ", vowels)
● Find the index of "o" and print that index value.
● index = vowels.index("o")
● print('The index of o:', index)
● Find the index of "e" and print that index value.
● index = vowels.index("e")
● print('The index of e:', index)
● Find the index of "u" and print that index value.
● index = vowels.index("u")
● print('The index of u:', index)
● Find the index of "a" and print that index value.
● index = vowels.index("a")
● print('The index of a:', index)
● Find all the index values of "i" and print those index value.
● i_vowel = [ i for i in range(len(vowels)) if vowels[i] == 'i' ]
● print('The index of a:',i_vowel)

 
Output :

●After running the code, output of the terminal as given below,




« Home

×